from django.shortcuts import render
from .models import Author,bookname
from frontname.models import Types
from django.http import HttpResponse
def index(request):
    # user = Author(name='吴承恩')
    # user.save()
    # bookn = bookname(name='西游记',content='第一章')
    # #Author是bookname的字段
    # bookn.Author = user
    # bookn.save()
    # author = Author(name = '老王')
    # author.save()
    # bookn = bookname(name = '老王烈火',content='第一章')
    # bookn.Author = author
    # bookn.save()
    return HttpResponse('success')
def one_tow(request):
    #1.一对多的关联操作
    # bookn = bookname(name='快乐',content='第一章')
    # author = Author.objects.first()  #拿到表里的第一条数据
    # type = Types.objects.first()
    # bookn.Author = author #指定外键
    # bookn.cate = type
    # bookn.save()

    #2.获取某个作者下的所有文章
    # author = Author.objects.first()
    # a = author.bookname_set.first()  #小寫模型名_set
    # print(a)
    a = bookname(name='111',content='222')
    author = Author.objects.first()
    a.Author = author
    type = Types.objects.first()
    a.cate = type
    a.save()

    return HttpResponse('sess')
